import { ApolloClient, InMemoryCache } from '@apollo/client/core'
import { provideApolloClient } from '@vue/apollo-composable'
import { link } from './config'

// 创建 apollo 客户端
export const apolloClient = new ApolloClient({
  link,
  // 缓存实现
  cache: new InMemoryCache(),

  // 缓存设置 从服务器获取数据
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'network-only'
    },
    query: {
      fetchPolicy: 'network-only'
    },
    mutate: {
      fetchPolicy: 'network-only'
    }
  },

  // 关闭开发工具提示
  connectToDevTools: false
})

// 注入
provideApolloClient(apolloClient)
